﻿using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Mgrs;
using Unity.VisualScripting;
using UnityEngine;

public class PlayerDashDown : PlayerBaseState {
	bool _animStart;
	public PlayerDashDown(PlayerController controller, PlayerStateEnum stateName, State<PlayerStateEnum> superFSM, StateFactory<PlayerStateEnum> factory) : base(controller, stateName, superFSM, factory) {
		AddConditionToSelf(() => controller.DownInput && controller.Jump);

	}

	public override void Enter() {
		_controller.PlayAnim(PlayerStateEnum.DashDownLoop);
		_controller.Velocity = new Vector2(0, _controller.ConfigData.DashDownSpeed);
		_animStart = false;
		_controller.StateData.IsDashOver = false;
		AudioManager.Play(_controller.Effect, AudioStr.PlayerDashDownBeginAudio, true);
		sendDmg = false;
		PoolTools.MakeShadowSyn(_controller.Velocity.normalized, _controller.GetSprite(), _controller.transform);
	}
	bool sendDmg;
	public override void Update() {
		//var tmp = true;
		if (_controller.IsOnGround && !_animStart) {
			CameraImpulseMgr.Instance.Generate(Vector2.down);
			AudioManager.Play(_controller.Effect, AudioStr.PlayerDashDownAudio);
			_controller.PlayAnim(PlayerStateEnum.DashDownOver);
			_animStart = true;
			//tmp = false;
		}
		else if (_animStart) {
			if (_controller.IsAnimPlayAt(0.65f) && !sendDmg) {
				PoolTools.MakeShadowSyn(_controller.Velocity.normalized, _controller.GetSprite(), _controller.transform);
				sendDmg = true;
				_controller.CheckAtk(_controller.ConfigData.DashDownOff, _controller.ConfigData.DashDownRad, _controller.ConfigData.SwdDamage);
			}
			if (_controller.IsAnimPlayOver()) {
				_controller.StateData.IsDashOver = true;
				PoolTools.MakeShadowSyn(_controller.Velocity.normalized, _controller.GetSprite(), _controller.transform);
			}
		}
		base.Update();
	}

	public override void Exit() {
	}
}